#pragma once

#include <engine.script/System.hpp>
#include "Component.hpp"




namespace Engine
{
	namespace Entity
	{
		class ScriptComponent
			: public Component
		{
		public:

			ScriptComponent(Script::ContextPool::ptr contextPool, Script::pointer<asIScriptObject> object);
			virtual ~ScriptComponent();



			virtual bool requiresUpdate() const;
			virtual void update();
			virtual ID id() const;



			virtual void attached(Entity::Object* entity, const map& components);
			virtual void detached(Entity::Object* entity);



			static void registerType(Script::System::ptr engine);

		protected:

			virtual void storeID();

		private:

			Script::ContextPool::ptr           m_contextPool;
			Script::pointer<asIScriptObject>   m_object;
			int                                m_componentId;
			int                                m_attachedId;
			int                                m_detachedId;
			int                                m_updateId;

			ID                                 m_id;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
